package com.zxw.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zxw.common.api.ApiResult;
import com.zxw.common.api.PageResult;
import com.zxw.common.constant.ApiConst;
import com.zxw.common.entity.gateway.BlackEntity;
import com.zxw.common.entity.gateway.BlackListQuery;
import com.zxw.common.entity.gateway.BlackQuery;
import com.zxw.common.entity.gateway.BlackVO;
import com.zxw.common.enums.ResultCode;
import com.zxw.user.service.BlackService;
import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 黑名单信息表接口
 * </p>
 *
 * @author zhanxuewei
 * @since 2022-10-10
 */
@Api(tags = "黑名单信息表接口", description = "BlackController")
@RestController
@RequestMapping(ApiConst.API_PREFIX + "/user/black")
public class BlackController {

    @Autowired
    private BlackService blackService;

    @PostMapping("/save")
    public ApiResult<ResultCode> save(@RequestBody BlackQuery blackQuery) {
        blackService.save(blackQuery);
        return ApiResult.success(ResultCode.SUCCESS);
    }

    @GetMapping("/pageList")
    public ApiResult<PageResult<BlackVO>> pageList(BlackListQuery blackListQuery) {
        IPage<BlackVO> ipage = blackService.pageList(blackListQuery);
        return ApiResult.success(PageResult.restPage(ipage, ipage.getRecords()));
    }

    @PostMapping("/saveBatch")
    public ApiResult<ResultCode> saveBatch(@RequestBody List<BlackQuery> list) {
        blackService.saveBatch(list);
        return ApiResult.success(ResultCode.SUCCESS);
    }

    @PostMapping("/update")
    public ApiResult<ResultCode> update(@RequestBody BlackQuery blackQuery) {
        blackService.updateById(blackQuery);
        return ApiResult.success(ResultCode.SUCCESS);
    }

    @PostMapping("/deletes")
    public ApiResult<ResultCode> deletes(@RequestBody List<String> ids) {
        blackService.removeByIds(ids);
        return ApiResult.success(ResultCode.SUCCESS);
    }

    @GetMapping("/detail/{id}")
    public ApiResult<BlackVO> detail(@PathVariable("id") String id) {
        BlackEntity blackEntity = blackService.getById(id);
        BlackVO blackVO = new BlackVO();
        BeanUtils.copyProperties(blackEntity, blackVO);
        return ApiResult.success(blackVO);
    }

    @GetMapping("/queryList")
    public ApiResult<List<BlackVO>> queryList() {
        List<BlackVO> list = blackService.queryList();
        return ApiResult.success(list);
    }

}

